﻿<%@ Page Language="VB" ValidateRequest="false" MasterPageFile="~/Default.master"
    Title="Untitled Page" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="ClubStarterKit.Data" %>

<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="~/UserControls/LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="~/UserControls/ImageThumbnail.ascx" %>
<%@ Register TagPrefix="Club" TagName="Photopicker" Src="~/UserControls/photos_formpicker.ascx" %>
<%@ Register TagPrefix="Club" TagName="Durationpicker" Src="~/UserControls/Durationpicker.ascx" %>
<%@ Register TagPrefix="Club" TagName="Locationpicker" Src="~/UserControls/Locations_picker.ascx" %>

<script runat="server">

    Private EventID, prevEventID, nextEventID As Integer
    Const INVALIDID As Integer = -1
    
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
        If Not IsPostBack Then
           
            Dim action As Object = Request.QueryString("Action")
            If Not action Is Nothing Then
                Select Case LCase(CStr(action))
                    case "new"
                        Response.Redirect("Add.aspx")
                    Case "delete"
                        ClubStarterKit.Web.Events.Delete(CStr(Request("ID")))
                        Response.Redirect("list.aspx")
                    Case Else                    
                        Dim ev As New ClubEvent(ClubEvent.Columns.Id, CStr(Request("ID")))
                        
                        FCKeditor1.Value = ev.Description
                        dtpicker.endDateTime = ev.Endtime
                        Photopicker1.ImageId = ev.Photo
                        chkRSVP.Checked = ev.Rsvp
                        dtpicker.startDateTime = ev.Starttime
                        staticURLTextBox.Text = ev.StaticURL
                        titleTextBox.Text = ev.Title
                        txtMaxAttendees.Text = ev.TotalAttendance.ToString()
                        LocationNameTXT.Text = ev.LocationName
                        FCKeditor2.Value = ev.LocationDirections
                        
                        If Not ev.StaticURL Is Nothing AndAlso ev.StaticURL <> "" Then
                            CheckBox1.Checked = True
                            staticURLTextBox.Enabled = True
                        Else
                            staticURLTextBox.Enabled = False
                        End If
                End Select
            End If
        End If
        Session("FCKeditor:UserFilesPath") = Request.ApplicationPath.ToString & "Files/"
    End Sub

    Protected Sub FormView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs)
        Response.Redirect("view.aspx?eventID=" & e.Keys("id").ToString)
    End Sub

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If CheckBox1.Checked Then
            staticURLTextBox.Enabled = True
        Else
            staticURLTextBox.Enabled = False
        End If
    End Sub

    Protected Sub apply1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Id As String = CStr(Request("ID"))
        Dim Description As String = FCKeditor1.Value.ToString()
        Dim Endtime As String = dtpicker.endDateTime.ToString()
        Dim Photo As String = Photopicker1.ImageId.ToString()
        Dim RSVP As String = chkRSVP.Checked.ToString()
        Dim Starttime As String = dtpicker.startDateTime.ToString()
        Dim staticurl As String = staticURLTextBox.Text.ToString()
        Dim ttl As String = titleTextBox.Text.ToString()
        Dim TotalAttendace As String = txtMaxAttendees.Text.ToString()
        Dim LocationName As String = LocationNameTXT.Text.ToString()
        Dim LocationDirections As String = FCKeditor2.Value.ToString()
        
        ClubStarterKit.Web.Events.Update(Id, Description, Endtime, LocationName, Photo, RSVP, Starttime, staticurl, ttl, TotalAttendace, LocationDirections)
        Response.Redirect("view.aspx?eventid=" & CStr(Request("ID")))
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="body">
    <asp:ScriptManager ID="Scriptmgnr" runat="server"></asp:ScriptManager>
        <Club:LoginBanner ID="LoginBanner1" runat="server" />
        <div class="actionbuttons">
            <Club:RolloverLink ID="Logoutbtn" runat="server" Text="New Event" OnClientClick="foo"
                NavigateURL="add.aspx" />
        </div>
        <div class="fullwidth">
            <h3>
                Event Details</h3>
            <div class="dashedline">
            </div>
            <table>
                <tr>
                    <td class="formlabel" style="height: 40px">
                        Event Heading:
                    </td>
                    <td align="left" style="height: 40px">
                        <asp:TextBox ID="titleTextBox" runat="server" Width="500px" Text='<%# Bind("Title") %>'></asp:TextBox>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please add a Heading." ControlToValidate="titleTextBox" ToolTip="Please add a Heading." ValidationGroup="edit">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Link:
                    </td>
                    <td align="left">
                        <asp:UpdatePanel ID="up1" runat="server">
                            <ContentTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" Text="Use a link instead of inline content for this anouncement:" /><br />
                                Link:
                                <asp:TextBox Text='<%# Bind("StaticURL") %>' runat="server" ID="staticURLTextBox"
                                    Width="450px" />
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Location Name:
                    </td>
                    <td align="left">
                        <asp:TextBox ID="LocationNameTXT" runat="server" Width="500px" Text=""></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Location Description:
                    </td>
                    <td align="left">
                        <FCKeditorV2:FCKeditor ID="FCKeditor2" runat="server" ToolbarSet="Default" SkinPath="skins/office2003/"
                            Value="" BasePath="~/FCKeditor/" UseBROnCarriageReturn="true">
                        </FCKeditorV2:FCKeditor>                            </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        <asp:Label ID="Label1" runat="server" Text="Description:" />
                    </td>
                    <td align="left">
                        <FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" ToolbarSet="Default" SkinPath="skins/office2003/"
                            Value='<%# Bind("Description") %>' BasePath="~/FCKeditor/" UseBROnCarriageReturn="true">
                        </FCKeditorV2:FCKeditor>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="FCKeditor1"
                            EnableClientScript="False" ErrorMessage="Please add a Description." ToolTip="Please add a Description."
                            ValidationGroup="edit">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Event Date:</td>
                    <td align="left">
                        <Club:Durationpicker ID="dtpicker" runat="server" startDateTime='<%#Bind("Starttime") %>'
                            endDateTime='<%#Bind("Endtime") %>' />
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Photo:</td>
                    <td align="left">
                        <Club:Photopicker ID="Photopicker1" runat="server" ImageId='<%# Bind("Photo") %>' />
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Want online sign-ups?</td>
                    <td align="left">
                        <asp:CheckBox runat="server" Checked='<%# Bind("RSVP") %>' ID="chkRSVP" />
                    </td>
                </tr>
                <tr>
                    <td class="formlabel">
                        Maximum attendees:<br />
                        (For Unlimited, type -1)
                    </td>
                    <td>
                        <asp:TextBox ID="txtMaxAttendees" runat="server" Width="50px" Text='<%# Bind("TotalAttendance") %>'></asp:TextBox>
                    </td>
                </tr>
            </table>
        <div class="dashedline">
        </div>
            <div class="actionbuttons">
                <Club:RolloverButton ID="apply1" Text="Apply" runat="server" ValidationGroup="edit" OnClick="apply1_Click" />
                <Club:RolloverLink ID="Cancel" Text="Cancel" runat="server" NavigateURL='<%# "view.aspx?EventID=" & Cstr(Eval("EventID")) %>' />
            </div>
        </div>
    </div>
</asp:Content>
